/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.cemaden.library.model.smp;

import br.gov.cemaden.library.model.BaseEntity;
import br.gov.cemaden.library.model.Usuario;
import br.gov.cemaden.library.model.pcds.Rede;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import org.hibernate.annotations.Type;

/**
 *
 * @author alan
 */
@Entity
@Table(name = "smp_log_rede", schema = "smp")
@SequenceGenerator(name = "sequence", sequenceName = "smp.smp_log_rede_sequence", schema = "smp")
@NamedQueries({
    @NamedQuery(name = "LogRede.findAll", query = "SELECT q FROM LogRede q ORDER BY q.id ASC"),
    @NamedQuery(name = "LogRede.findByRede", query = "SELECT q FROM LogRede q WHERE q.rede = :rede")
})
public class LogRede implements Serializable, BaseEntity{
    
    @Id
    @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
    @Column(name = "id_log_rede", nullable = false, unique = true)
    private Long id;
    
    @Lob
    @Type(type = "org.hibernate.type.TextType")
    @Column(name = "notificacao")
    private String notificacao;
        
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Column(name = "datahora")
    private Date datahora;
    
    @ManyToOne(optional = false)
    @JoinColumn(name = "id_rede", referencedColumnName = "id_rede")
    private Rede rede;
    
    @ManyToMany
    @JoinTable(name = "smp_log_rede_usuario", schema = "smp",
            joinColumns = {@JoinColumn(name = "id_log_rede")},
            inverseJoinColumns = {@JoinColumn(name = "id_usuario")})
    private Set<Usuario> usuarios = new HashSet<Usuario>();

    public LogRede(){
        
    }
    
    public LogRede(Rede rede, String notificacao, Date datahora, Set<Usuario> usuarios){
        this.rede = rede;
        this.notificacao = notificacao;
        this.datahora = datahora;
        this.usuarios = usuarios;
    }
    
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the notificacao
     */
    public String getNotificacao() {
        return notificacao;
    }

    /**
     * @param notificacao the notificacao to set
     */
    public void setNotificacao(String notificacao) {
        this.notificacao = notificacao;
    }

    /**
     * @return the datahora
     */
    public Date getDatahora() {
        return datahora;
    }

    /**
     * @param datahora the datahora to set
     */
    public void setDatahora(Date datahora) {
        this.datahora = datahora;
    }
    
    /**
     * @return the rede
     */
    public Rede getRede() {
        return rede;
    }

    /**
     * @param rede the rede to set
     */
    public void setRede(Rede rede) {
        this.rede = rede;
    }

    /**
     * @return the usuarios
     */
    public Set<Usuario> getUsuarios() {
        return usuarios;
    }

    /**
     * @param usuarios the usuarios to set
     */
    public void setUsuarios(Set<Usuario> usuarios) {
        this.usuarios = usuarios;
    }    
    
}
